package com.example.swagger.mapper;

import com.example.swagger.entity.BookEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper

public interface BookMapper {

    @Select("SELECT * FROM book")
    public List<BookEntity> getBooks();

    @Insert("INSERT INTO book(id, name, isOnsale, price, publish_date, author_name) VALUES (#{id},#{name},#{isOnsale},#{price},#{publish_date},#{author_name})")
    void insertBookRecord(@Param("id") Integer id, @Param("name") String name, @Param("isOnsale") boolean isOnsale, @Param("price") float price, @Param("publish_date") Date publish_date, @Param("author_name") String author_name);

    @Select("SELECT * FROM book WHERE id=#{id}")
    public BookEntity findBookById(Integer id);

    @Delete("DELETE FROM book WHERE id = ${id}")
    void deleteFromBook(@Param("id") Integer id);

    @Update("update book set name=#{name}, isOnsale=#{isOnsale}, price=#{price}, publish_date=#{publish_date}, author_name=#{author_name} WHERE id=#{id}")
    public BookEntity updateBook(@Param("id") Integer id,@Param("name") String name,@Param("isOnsale") boolean isOnsale,@Param("price") float price,@Param("publish_date") Date publish_date,@Param("author_name") String author_name);

}
